
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>DEMO</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/jquery.json.min.js"></script>

    <script type="text/javascript" language="JavaScript">

        function save() {
            var sqlList = {};
            sqlList["sql1"] = "select * from pushtest1";
            sqlList["sql2"] = "select *  from  pushtest2";


            var dataSourceObj = {};
            dataSourceObj = {"dataSourceName": "testdb", "dataSourceURL": "jdbc:oracle:thin:@localhost:1521:ORCL", "userName": "demo", "password": "123", "sqlListVo": {"sql1": "select ", "sql2": "sleet3"}};
            alert(jQuery.toJSON(dataSourceObj));
            jQuery.ajax({
                url: "/dataSource/save.ipush",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(dataSourceObj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    //alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);
                }
            });

        }

        function queryList() {

            var dataSourceObj = {};
            dataSourceObj = {"dataSourceName": "testdb"};
            alert(jQuery.toJSON(dataSourceObj));
            jQuery.ajax({
                url: "/dataSource/queryList.ipush",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(dataSourceObj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    //alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);

                }
            });
        }
        function querySingle() {

            var dataSourceObj = {};
            dataSourceObj = {"dataSourceModelId": "c465317882254dcf8806d0edc67386a1"};
            alert(jQuery.toJSON(dataSourceObj));
            jQuery.ajax({
                url: "/dataSource/querySingle.ipush",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(dataSourceObj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    //alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);
                }
            });
        }

        function queryListByPage() {

            var dataSourceObj = {};
            dataSourceObj = {"dataSourceName": "testdb", "curPage": 1, "itemsPerPage": 3};
            alert(jQuery.toJSON(dataSourceObj));
            jQuery.ajax({
                url: "/dataSource/queryListByPage.ipush",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(dataSourceObj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    //alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);
                }
            });
        }

        function queryAll() {

            jQuery.ajax({
                url: "/dataSource/queryAll.ipush",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    //alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);
                }
            });
        }

        function updateDataSource() {

            var dataSourceObj = {};
            dataSourceObj = {"dataSourceModelId": "c465317882254dcf8806d0edc67386a1", "dataSourceName": "testdb", "dataSourceURL": "jdbc:oracle:thin:@localhost:1521:ORCL", "userName": "demo", "password": "123", "sqlListVo": {"sql1": "select ", "sql2": "sleet3"}};
            alert(jQuery.toJSON(dataSourceObj));
            jQuery.ajax({
                url: "/dataSource/update.ipush",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(dataSourceObj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    //alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);
                }
            });
        }

        function deleteDataSource() {

            var dataSourceObj = {};
            dataSourceObj = {"dataSourceModelId": "c465317882254dcf8806d0edc67386a1"};
            alert(jQuery.toJSON(dataSourceObj));
            jQuery.ajax({
                url: "/dataSource/delete",
                type: "POST",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
                data: jQuery.toJSON(dataSourceObj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
                success: function (data) {
                    // alert(JSON.stringify(data));
                    jQuery("#content").html(JSON.stringify(data));
                },
                error: function (res) {
                    alert(res.responseText);
                }
            });
        }
    </script>

</head>
<body>
<h1>DEMO-增删改查</h1>
<input id="submit" type="button" value="save" onclick="save();">
<input id="submit1" type="button" value="updateDataSource" onclick="updateDataSource();">
<input id="submit2" type="button" value="deleteDataSource" onclick="deleteDataSource();">
<input id="submit3" type="button" value="querySingle" onclick="querySingle();">
<input id="submit4" type="button" value="queryAll" onclick="queryAll();">
<input id="submit5" type="button" value="queryListByPage" onclick="queryListByPage();">
<input id="submit6" type="button" value="queryList" onclick="queryList();">

<H1>返回内容</H1>

<div id="content" style="border-color: red">

</div>
</body>
</html>